package com.net.xpay.web.controller.merchant.safePay;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.net.xpay.web.vo.ExcelErrDataVo;
import com.net.xpay.web.vo.SafePayBatchVo;
import com.net.common.annotation.WriteTransactional;
import com.net.common.exception.BusinessException;
import com.net.common.model.ResultData;
import com.net.common.util.PhoneUtil;
import com.net.common.util.SerializationUtil;
import com.net.common.util.StreamUtil;
import com.net.xpay.common.domain.SafePayExcelTemplate;
import com.net.xpay.common.domain.User;
import com.net.xpay.common.domain.UserProfile;
import com.net.xpay.common.manager.SafePayExcelTemplateManager;
import com.net.xpay.common.manager.UserProfileManager;
import com.net.xpay.core.constant.PoseidonErrorCode;
import com.net.xpay.core.constant.TransBizTypeConstant;
import com.net.xpay.core.domain.safePay.SafePayBatch;
import com.net.xpay.core.enums.PayeeType;
import com.net.xpay.core.helper.UploadHelper;
import com.net.xpay.core.manager.safePay.SafePayBatchManager;
import com.net.xpay.core.model.ResultModel;
import com.net.xpay.core.model.SafePayBatchCreateModel;
import com.net.xpay.core.model.SafePayTransModel;
import com.net.xpay.core.service.safePay.SafePayService;
import com.net.xpay.core.utils.BankUtil;
import com.net.xpay.core.utils.BeanCopierUtil;
import com.net.xpay.core.utils.EmailUtil;
import com.net.xpay.core.utils.ExcelImportUtil;
import com.net.xpay.web.secutiry.RequestUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.function.Function;

/**
 * 2020/5/7 13:31

 */
@RestController
@Slf4j
@RequestMapping("/merchant/excel")
@Api(tags = "商户/手动导入打款名单导入", description = "商户 手动导入打款名单导入 net")
public class SafePayTransImportController {

    @Autowired
    private SafePayBatchManager safePayBatchManager;

    @Autowired
    private SafePayService safePayService;

    @Autowired
    private UploadHelper uploadHelper;

    @Autowired
    private SafePayExcelTemplateManager safePayExcelTemplateManager;

    @Autowired
    private UserProfileManager userProfileManager;

    /**
     * 安全付手动导入打款名单导入
     */
    @ApiOperation("安全付手动导入打款名单导入")
    @PostMapping("/import-safe-pay-trans")
    @WriteTransactional
    public ResultData<SafePayBatchVo> importSafePayTrans(@RequestParam(value = "file", required = false) MultipartFile file, @ApiIgnore @RequestUser User merchant, String alipayNickName, Integer type, String orderTitle) {
        Preconditions.checkArgument(file != null);
        UserProfile userProfile = userProfileManager.getById(merchant.getId());
        if (Boolean.TRUE.equals(userProfile.getLimitSafePayWebPageTrans())) {
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "权限未开通");
        }

        String fileName = file.getOriginalFilename();
        Preconditions.checkArgument(!Strings.isNullOrEmpty(fileName));
        if (!(fileName.endsWith("xls") || fileName.endsWith("xlsx"))) {
            log.warn("importSafePayTrans file suffix error：" + fileName);
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "上传的文件格式错误|" + fileName);
        }
        long size = file.getSize();

        if (size > 10 * 1024 * 1024L) {
            log.warn("importSafePayTrans|file is too large|fileSize={}|userId={}", size, merchant.getId());
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "上传文件最大10M");
        }

        try {
            Workbook workBook = ExcelImportUtil.getWorkbook(file.getOriginalFilename(), file.getInputStream());
            Sheet sheet = workBook.getSheetAt(0);
            ResultModel<List<String>> resultModel = ExcelImportUtil.importListFromExcelUtilNull(workBook, sheet, 1, null);
            log.info("importWithdrawRecord resultModel={}", SerializationUtil.obj2String(resultModel));
            if (!resultModel.isSuccess()) {
                throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, resultModel.getResultMessage());
            }

            String batchId = getBatchId(sheet, workBook);
            if (Strings.isNullOrEmpty(batchId)) {
                batchId = TransBizTypeConstant.AUTO + System.currentTimeMillis();
            }

            List<SafePayTransModel> payTrans = checkImportData(batchId, resultModel.getData(), merchant, type,orderTitle);

            SafePayBatchCreateModel safePayBatchCreateModel = buildSafePayBatchCreateModel(batchId, alipayNickName, payTrans, type);

            //是否需要短信验证
            if (Boolean.TRUE.equals(userProfile.getBatchEnsure())) {
                safePayBatchCreateModel.setBatchEnsure(true);
            }
            SafePayBatch safePayBatch = safePayService.createSafePayBatch(merchant, safePayBatchCreateModel);

            //将文件保存起来 7天有效期
            LocalDateTime expired = LocalDateTime.now().plusDays(7L);
            String fileUrl = uploadHelper.upload("(" + UUID.randomUUID().toString().replace("-", "") + ")" + file.getOriginalFilename(), file.getInputStream(), expired);
            safePayBatch.setFileUrl(fileUrl);
            safePayBatch.setFileExpired(expired);
            safePayBatchManager.updateByPrimaryKeyWithVersion(safePayBatch);

            //保存导入记录
            SafePayBatchVo vo = SafePayBatchVo.getInstance();
            BeanCopierUtil.copy(safePayBatch, vo);
            return new ResultData<>(vo);
        } catch (IOException e) {
            log.info("importSafePayTrans error", e);
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "系统错误 请联系客服");
        }
    }



    /**
     * 安全付自定义表格导入打款名单导入
     */
    @ApiOperation("安全付自定义表格导入打款名单导入")
    @PostMapping("/import-custom-template")
    @WriteTransactional
    public ResultData<SafePayBatchVo> importCustomTemplate(@RequestParam(value = "file", required = false) MultipartFile file, @ApiIgnore @RequestUser User merchant, String alipayNickName, Integer type, Long templateId,String orderTitle) {
        Preconditions.checkArgument(file != null);
        if (templateId == null) {
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "请选择自定义表格模板");
        }
        UserProfile userProfile = userProfileManager.getById(merchant.getId());
        if (Boolean.TRUE.equals(userProfile.getLimitSafePayWebPageTrans())) {
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "权限未开通");
        }

        String fileName = file.getOriginalFilename();
        Preconditions.checkArgument(!Strings.isNullOrEmpty(fileName));
        if (!(fileName.endsWith("xls") || fileName.endsWith("xlsx"))) {
            log.warn("importCustomTemplate file suffix error：" + fileName);
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "上传的文件格式错误|" + fileName);
        }
        long size = file.getSize();

        if (size > 10 * 1024 * 1024L) {
            log.warn("importCustomTemplate|file is too large|fileSize={}|userId={}", size, merchant.getId());
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "上传文件最大10M");
        }

        try {
            Workbook workBook = ExcelImportUtil.getWorkbook(file.getOriginalFilename(), file.getInputStream());
            Sheet sheet = workBook.getSheetAt(0);
            ResultModel<List<String>> resultModel = ExcelImportUtil.importListFromExcelUtilNull(workBook, sheet, 0, null);
            log.info("importCustomTemplate resultModel={}", SerializationUtil.obj2String(resultModel));
            if (!resultModel.isSuccess()) {
                throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, resultModel.getResultMessage());
            }

            String batchId = TransBizTypeConstant.AUTO + System.currentTimeMillis();

            List<SafePayTransModel> payTrans = checkCustomImportData(batchId, resultModel.getData(), merchant, type, templateId,orderTitle);

            SafePayBatchCreateModel safePayBatchCreateModel = buildSafePayBatchCreateModel(batchId, alipayNickName, payTrans, type);
            if (Boolean.TRUE.equals(userProfile.getBatchEnsure())) {
                safePayBatchCreateModel.setBatchEnsure(true);
            }
            SafePayBatch safePayBatch = safePayService.createSafePayBatch(merchant, safePayBatchCreateModel);

            //将文件保存起来 7天有效期
            LocalDateTime expired = LocalDateTime.now().plusDays(7L);
            String fileUrl = uploadHelper.upload("(" + UUID.randomUUID().toString().replace("-", "") + ")" + file.getOriginalFilename(), file.getInputStream(), expired);
            safePayBatch.setFileUrl(fileUrl);
            safePayBatch.setFileExpired(expired);
            safePayBatchManager.updateByPrimaryKeyWithVersion(safePayBatch);

            //保存导入记录
            SafePayBatchVo vo = SafePayBatchVo.getInstance();
            BeanCopierUtil.copy(safePayBatch, vo);
            return new ResultData<>(vo);
        } catch (IOException e) {
            log.info("importSafePayTrans error", e);
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "系统错误 请联系客服");
        }
    }


    private SafePayBatchCreateModel buildSafePayBatchCreateModel(String batchId, String alipayNickName, List<SafePayTransModel> payTrans, Integer type) throws IOException {
        SafePayBatchCreateModel safePayBatchCreateModel = new SafePayBatchCreateModel();
        safePayBatchCreateModel.setPayTrans(payTrans);
        safePayBatchCreateModel.setImportBatchNo(batchId);
        safePayBatchCreateModel.setAlipayNickName(alipayNickName);
        safePayBatchCreateModel.setNeedNotify(false);
        safePayBatchCreateModel.setType(type == null ? PayeeType.ALIPAY : PayeeType.get(type));
        Function<SafePayTransModel, BigDecimal> sum = ins -> new BigDecimal(ins.getTransAmount());
        safePayBatchCreateModel.setTotalTransAmount(StreamUtil.sum(payTrans, sum).toString());
        safePayBatchCreateModel.setTotalCount((long) payTrans.size());

        return safePayBatchCreateModel;
    }

    private List<SafePayTransModel> checkImportData(String batchId, List<List<String>> datas, User merchant, Integer type, String orderTitle) {
        SafePayBatch batch = safePayBatchManager.findByImportBatchNo(merchant.getId(), batchId);
        if (batch != null) {
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "该业务批次号已被使用：" + batchId);
        }

        List<SafePayTransModel> payTrans = Lists.newArrayList();
        List<String> importBizNos = Lists.newArrayList();
        StringBuilder errMessage = new StringBuilder();
        // excel错误行数据
        List<ExcelErrDataVo> errDataVoList = new ArrayList<>();
        //第一行是标题行
        for (int i = 1; i < datas.size(); i++) {
            List<String> row = datas.get(i);
            String alipayNo = row.get(0);
            String name = row.get(1);
            String money = row.get(2);
            String importBizNo = row.get(3);
            if (Strings.isNullOrEmpty(importBizNo)) {
                //没上传的自动生成一个编号
                importBizNo = String.valueOf(i);
            }
            String remark = row.get(4);

            //一个批次订单编号不能重复
            if (importBizNos.contains(importBizNo)) {
                errMessage.append(" (第").append(i + 2).append("行:").append("订单编号重复) ");
                fillErrExcelData(i, datas, errDataVoList, "订单编号重复");
                continue;
            }
            importBizNos.add(importBizNo);

            //买家昵称 和 支付宝账号&真实姓名 二选一必填一项
            if (Strings.isNullOrEmpty(name)) {
                errMessage.append(" (第").append(i + 2).append("行:").append("真实姓名必填");
                fillErrExcelData(i, datas, errDataVoList, "真实姓名必填");
                continue;
            }

            if (Strings.isNullOrEmpty(money)) {
                errMessage.append(" (第").append(i + 2).append("行:").append("打款金额不能为空) ");
                fillErrExcelData(i, datas, errDataVoList, "打款金额不能为空");
                continue;
            }

            SafePayTransModel instance = new SafePayTransModel();
            instance.setImportBizNo(importBizNo);
            instance.setTransAmount(money);
            instance.setRemark(remark);
            instance.setName(name);

            if (type != null && PayeeType.BANK.getValue() == type) {
                if (Strings.isNullOrEmpty(alipayNo)) {
                    errMessage.append(" (第").append(i + 2).append("行:").append("请填写银行卡号) ");
                    fillErrExcelData(i, datas, errDataVoList, "请填写银行卡号");
                    continue;
                }
                //去除制表符
                alipayNo = alipayNo.replace("\t", "");
                if (alipayNo.contains(" ")) {
                    errMessage.append(" (第").append(i + 2).append("行:").append("银行卡号不能有空格) ");
                    fillErrExcelData(i, datas, errDataVoList, "银行卡号不能有空格");
                    continue;
                }
                //银行卡
                if (!BankUtil.isValid(alipayNo)) {
                    errMessage.append(" (第").append(i + 2).append("行:").append("银行卡号格式错误) ");
                    fillErrExcelData(i, datas, errDataVoList, "银行卡号格式错误");
                    continue;
                }
            } else {
                if (Strings.isNullOrEmpty(alipayNo)) {
                    errMessage.append(" (第").append(i + 2).append("行:").append("请填写支付宝账号) ");
                    fillErrExcelData(i, datas, errDataVoList, "请填写支付宝账号");
                    continue;
                }
                //去除制表符
                alipayNo = alipayNo.replace("\t", "");
                //支付宝
                if (!Strings.isNullOrEmpty(alipayNo) && !Strings.isNullOrEmpty(name)) {
                    if (alipayNo.contains(" ")) {
                        errMessage.append(" (第").append(i + 2).append("行:").append("支付宝账号不能有空格) ");
                        fillErrExcelData(i, datas, errDataVoList, "支付宝账号不能有空格");
                        continue;
                    }
                    if (!alipayNo.contains("@")) {
                        if (!PhoneUtil.isEffectiveMobile(alipayNo)) {
                            errMessage.append(" (第").append(i + 2).append("行:").append("支付宝账号格式错误) ");
                            fillErrExcelData(i, datas, errDataVoList, "支付宝账号格式错误");
                            continue;
                        }
                    } else {
                        if (!EmailUtil.checkEmail(alipayNo)) {
                            errMessage.append(" (第").append(i + 2).append("行:").append("支付宝账号格式错误) ");
                            fillErrExcelData(i, datas, errDataVoList, "支付宝账号格式错误");
                            continue;
                        }
                    }
                }
            }

            instance.setIdentity(alipayNo);

            checkIsDigit(i, money, errMessage, datas, errDataVoList);
            instance.setOrderTitle(orderTitle);
            payTrans.add(instance);
        }

        if (!Strings.isNullOrEmpty(errMessage.toString())) {
            // 将errDataVoList转为string
            String err = SerializationUtil.obj2String(errDataVoList);
            throw new BusinessException(PoseidonErrorCode.EXCEL_DATA_ILLEGAL, err);
        }

        if (CollectionUtils.isEmpty(payTrans)) {
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "至少上传一条打款记录");
        }

        return payTrans;
    }


    private List<SafePayTransModel> checkCustomImportData(String batchId, List<List<String>> datas, User merchant, Integer type, Long templateId, String orderTitle) {
        SafePayExcelTemplate template = safePayExcelTemplateManager.findById(merchant.getId(), templateId);
        if (template == null) {
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "自定义表格不存在");
        }


        SafePayBatch batch = safePayBatchManager.findByImportBatchNo(merchant.getId(), batchId);
        if (batch != null) {
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "该业务批次号已被使用：" + batchId);
        }

        List<SafePayTransModel> payTrans = Lists.newArrayList();
        List<String> importBizNos = Lists.newArrayList();
        StringBuilder errMessage = new StringBuilder();
        // excel错误行数据
        List<ExcelErrDataVo> errDataVoList = new ArrayList<>();
        //第一行是标题行
        for (int i = 1; i < datas.size(); i++) {
            List<String> row = datas.get(i);
            String alipayNo;
            String name;
            String money;
            try {
                alipayNo = row.get(template.getIdentityColumnIndex() - 1);
                name = row.get(template.getNameColumnIndex() - 1);
                money = row.get(template.getAmountColumnIndex() - 1);
            } catch (Exception e) {
                throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "自定义表格配置错误,无法解析表格");
            }

            String importBizNo = String.valueOf(i);
            String remark = "";
            //一个批次订单编号不能重复
            if (importBizNos.contains(importBizNo)) {
                errMessage.append(" (第").append(i + 1).append("行:").append("订单编号重复) ");
                fillCustomErrExcelData(template, i, datas, errDataVoList, "订单编号重复");
                continue;
            }
            importBizNos.add(importBizNo);

            //买家昵称 和 支付宝账号&真实姓名 二选一必填一项
            if (Strings.isNullOrEmpty(name)) {
                errMessage.append(" (第").append(i + 1).append("行:").append("真实姓名必填");
                fillCustomErrExcelData(template, i, datas, errDataVoList, "真实姓名必填");
                continue;
            }

            if (Strings.isNullOrEmpty(money)) {
                errMessage.append(" (第").append(i + 1).append("行:").append("打款金额不能为空) ");
                fillCustomErrExcelData(template, i, datas, errDataVoList, "打款金额不能为空");
                continue;
            }

            SafePayTransModel instance = new SafePayTransModel();
            instance.setImportBizNo(importBizNo);
            instance.setTransAmount(money);
            instance.setRemark(remark);
            instance.setName(name);

            if (type != null && PayeeType.BANK.getValue() == type) {
                if (Strings.isNullOrEmpty(alipayNo)) {
                    errMessage.append(" (第").append(i + 1).append("行:").append("请填写银行卡号) ");
                    fillCustomErrExcelData(template, i, datas, errDataVoList, "请填写银行卡号");
                    continue;
                }
                //去除制表符
                alipayNo = alipayNo.replace("\t", "");
                if (alipayNo.contains(" ")) {
                    errMessage.append(" (第").append(i + 1).append("行:").append("银行卡号不能有空格) ");
                    fillCustomErrExcelData(template, i, datas, errDataVoList, "银行卡号不能有空格");
                    continue;
                }
                //银行卡
                if (!BankUtil.isValid(alipayNo)) {
                    errMessage.append(" (第").append(i + 1).append("行:").append("银行卡号格式错误) ");
                    fillCustomErrExcelData(template, i, datas, errDataVoList, "银行卡号格式错误");
                    continue;
                }
            } else {
                if (Strings.isNullOrEmpty(alipayNo)) {
                    errMessage.append(" (第").append(i + 1).append("行:").append("请填写支付宝账号) ");
                    fillCustomErrExcelData(template, i, datas, errDataVoList, "请填写支付宝账号");
                    continue;
                }
                //去除制表符
                alipayNo = alipayNo.replace("\t", "");
                //支付宝
                if (!Strings.isNullOrEmpty(alipayNo) && !Strings.isNullOrEmpty(name)) {
                    if (alipayNo.contains(" ")) {
                        errMessage.append(" (第").append(i + 1).append("行:").append("支付宝账号不能有空格) ");
                        fillCustomErrExcelData(template, i, datas, errDataVoList, "支付宝账号不能有空格");
                        continue;
                    }
                    if (!alipayNo.contains("@")) {
                        if (!PhoneUtil.isEffectiveMobile(alipayNo)) {
                            errMessage.append(" (第").append(i + 1).append("行:").append("支付宝账号格式错误) ");
                            fillCustomErrExcelData(template, i, datas, errDataVoList, "支付宝账号格式错误");
                            continue;
                        }
                    } else {
                        if (!EmailUtil.checkEmail(alipayNo)) {
                            errMessage.append(" (第").append(i + 1).append("行:").append("支付宝账号格式错误) ");
                            fillCustomErrExcelData(template, i, datas, errDataVoList, "支付宝账号格式错误");
                            continue;
                        }
                    }
                }
            }

            instance.setIdentity(alipayNo);

            checkCustomIsDigit(template, i, money, errMessage, datas, errDataVoList);
            instance.setOrderTitle(orderTitle);

            payTrans.add(instance);
        }

        if (!Strings.isNullOrEmpty(errMessage.toString())) {
            // 将errDataVoList转为string
            String err = SerializationUtil.obj2String(errDataVoList);
            throw new BusinessException(PoseidonErrorCode.EXCEL_DATA_ILLEGAL, err);
        }

        if (CollectionUtils.isEmpty(payTrans)) {
            throw new BusinessException(PoseidonErrorCode.PARAMETER_ILLEGAL, "至少上传一条打款记录");
        }

        return payTrans;
    }


    private void checkIsDigit(int i, String money, StringBuilder errMessage, List<List<String>> datas, List<ExcelErrDataVo> errDataVoList) {
        BigDecimal m;
        try {
            m = new BigDecimal(money);
        } catch (Exception e) {
            errMessage.append(" (第").append(i + 2).append("行:").append("打款金额格式不正确) ");
            fillErrExcelData(i, datas, errDataVoList, "打款金额格式不正确");
            return;
        }

        if (m.compareTo(new BigDecimal("0.1")) < 0) {
            errMessage.append(" (第").append(i + 2).append("行:").append("打款金额不能低于0.1元) ");
            fillErrExcelData(i, datas, errDataVoList, "打款金额不能低于0.1元");
            return;
        }

        if (m.intValue() > 50000) {
            errMessage.append(" (第").append(i + 2).append("行:").append("打款金额不能大于50000元) ");
            fillErrExcelData(i, datas, errDataVoList, "打款金额不能大于50000元");
        }
    }


    private void checkCustomIsDigit(SafePayExcelTemplate template, int i, String money, StringBuilder errMessage, List<List<String>> datas, List<ExcelErrDataVo> errDataVoList) {
        BigDecimal m;
        try {
            m = new BigDecimal(money);
        } catch (Exception e) {
            errMessage.append(" (第").append(i + 1).append("行:").append("打款金额格式不正确) ");
            fillCustomErrExcelData(template, i, datas, errDataVoList, "打款金额格式不正确");
            return;
        }

        if (m.compareTo(new BigDecimal("0.1")) < 0) {
            errMessage.append(" (第").append(i + 1).append("行:").append("打款金额不能低于0.1元) ");
            fillCustomErrExcelData(template, i, datas, errDataVoList, "打款金额不能低于0.1元");
            return;
        }

        if (m.intValue() > 50000) {
            errMessage.append(" (第").append(i + 1).append("行:").append("打款金额不能大于50000元) ");
            fillCustomErrExcelData(template, i, datas, errDataVoList, "打款金额不能大于50000元");
        }
    }

    private String getBatchId(Sheet sheet, Workbook workBook) {
        ResultModel<List<String>> resultModel = ExcelImportUtil.importListFromExcelUtilNull(workBook, sheet, 0, 0);
        String batchId;
        try {
            batchId = resultModel.getData().get(0).get(5);
        } catch (Exception e) {
            return null;
        }

        return batchId;
    }

    /**
     * @param row   : 行数
     * @param datas : excel总数据
     * @Description:[将excel中错误的数据封装到ExcelErrDataVo对象]

     * @date 2020/11/3 11:46
     */
    private void fillErrExcelData(Integer row, List<List<String>> datas, List<ExcelErrDataVo> errDataVoList, String errMsg) {
        ExcelErrDataVo excelErrDataVo = new ExcelErrDataVo();
        // 获取list集合中指定索引的数据
        List<String> list = datas.get(row);
        // 封装excelErrDataVo对象
        excelErrDataVo.setRow(row + 2);
        excelErrDataVo.setAlipayNo(list.get(0));
        excelErrDataVo.setName(list.get(1));
        excelErrDataVo.setMoney(list.get(2));
        excelErrDataVo.setImportBizNo(list.get(3));
        excelErrDataVo.setRemark(list.get(4));
        excelErrDataVo.setErrMsg(errMsg);
        errDataVoList.add(excelErrDataVo);
    }


    private void fillCustomErrExcelData(SafePayExcelTemplate template, Integer row, List<List<String>> datas, List<ExcelErrDataVo> errDataVoList, String errMsg) {
        ExcelErrDataVo excelErrDataVo = new ExcelErrDataVo();
        // 获取list集合中指定索引的数据
        List<String> list = datas.get(row);
        // 封装excelErrDataVo对象
        excelErrDataVo.setRow(row + 1);
        excelErrDataVo.setAlipayNo(list.get(template.getIdentityColumnIndex() - 1));
        excelErrDataVo.setName(list.get(template.getNameColumnIndex() - 1));
        excelErrDataVo.setMoney(list.get(template.getAmountColumnIndex() - 1));
        excelErrDataVo.setImportBizNo(null);
        excelErrDataVo.setRemark(null);
        excelErrDataVo.setErrMsg(errMsg);
        errDataVoList.add(excelErrDataVo);
    }


}
